<?php
/* Author: tbloc@cantho.gov.vn */
class Chi_tiet_xuat{  
//Properties
private $HH_ID;
private $XUAT_ID;
private $DON_GIA;
private $SO_LUONG;
private $THANH_TIEN;
private $IS_ACTIVE;
//properties set get 
public function setHH_ID($HH_ID) 
{
	$this->HH_ID = $HH_ID;
}
public function getHH_ID()
{
	return $this->HH_ID;
}	        
public function setXUAT_ID($XUAT_ID) 
{
	$this->XUAT_ID = $XUAT_ID;
}
public function getXUAT_ID()
{
	return $this->XUAT_ID;
}	        
public function setDON_GIA($DON_GIA) 
{
	$this->DON_GIA = $DON_GIA;
}
public function getDON_GIA()
{
	return $this->DON_GIA;
}	        
public function setSO_LUONG($SO_LUONG) 
{
	$this->SO_LUONG = $SO_LUONG;
}
public function getSO_LUONG()
{
	return $this->SO_LUONG;
}	        
public function setTHANH_TIEN($THANH_TIEN) 
{
	$this->THANH_TIEN = $THANH_TIEN;
}
public function getTHANH_TIEN()
{
	return $this->THANH_TIEN;
}	        
public function setIS_ACTIVE($IS_ACTIVE) 
{
	$this->IS_ACTIVE = $IS_ACTIVE;
}
public function getIS_ACTIVE()
{
	return $this->IS_ACTIVE;
}	        
//crud methods
public function insert($db = null) {
	if ($db != null){
	$sql = "INSERT INTO `chi_tiet_xuat`(                        
			`HH_ID`, 
				`XUAT_ID`, 
				`DON_GIA`, 
				`SO_LUONG`, 
				`THANH_TIEN`, 
				`IS_ACTIVE` 
		)
	VALUES(
    		:HH_ID, 
	    		:XUAT_ID, 
	    		:DON_GIA, 
	    		:SO_LUONG, 
	    		:THANH_TIEN, 
	    		:IS_ACTIVE 
	    );";
	$parameters = array(
			":HH_ID", 
				":XUAT_ID", 
				":DON_GIA", 
				":SO_LUONG", 
				":THANH_TIEN", 
				":IS_ACTIVE" 
		);
    $values = array(  
    		$this->getHH_ID(), 
	    		$this->getXUAT_ID(), 
	    		$this->getDON_GIA(), 
	    		$this->getSO_LUONG(), 
	    		$this->getTHANH_TIEN(), 
	    		$this->getIS_ACTIVE() 
	    );
    $types = array(
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    );
	$lastInsertID = $db->executeNonQuery($sql, $parameters, $values, $types, true);
	$this->setXUAT_ID($lastInsertID);
    }
}
	
	public function delete($db = null) {
	    if ($db != null) {
	        $sql = "delete FROM `chi_tiet_xuat`
	                where `XUAT_ID` = :XUAT_ID;";
	        $parameters = array(":XUAT_ID");
	        $values = array($this->getXUAT_ID());
	        $types = array(PDO::PARAM_INT);//Kiem tra lai kieu du lieu nhe
	        $result = $db->executeNonQuery($sql, $parameters, $values, $types);
	        return $result;
	    }
	}
	
	public function update($db = null) {
	        if ($db != null) {
	            $sql = "UPDATE `chi_tiet_xuat` SET 
			`HH_ID`=:HH_ID,
				`XUAT_ID`=:XUAT_ID,
				`DON_GIA`=:DON_GIA,
				`SO_LUONG`=:SO_LUONG,
				`THANH_TIEN`=:THANH_TIEN,
				`IS_ACTIVE`=:IS_ACTIVE
			WHERE `XUAT_ID` = :XUAT_ID;";
	            $parameters = array(
			":HH_ID",
				":XUAT_ID",
				":DON_GIA",
				":SO_LUONG",
				":THANH_TIEN",
				":IS_ACTIVE"
			);
	// Kiem tra dau , nhe
	$values = array(  
			$this->getHH_ID(),
				$this->getXUAT_ID(),
				$this->getDON_GIA(),
				$this->getSO_LUONG(),
				$this->getTHANH_TIEN(),
				$this->getIS_ACTIVE()
		);
    $types = array(
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
    	PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
    );
	$result = $db->executeNonQuery($sql, $parameters, $values, $types);
	return $result;
	        }
	 }
	 
	public function getByID($thu,$hanghoa,$db = null) {
	if ($db != null) {
	$sql = "SELECT
			`HH_ID`,
				`XUAT_ID`,
				`DON_GIA`,
				`SO_LUONG`,
				`THANH_TIEN`,
				`IS_ACTIVE`
			FROM `chi_tiet_xuat` WHERE `XUAT_ID` = :XUAT_ID and `HH_ID`=:HH_ID and `is_active`=1;";
	$parameters = array(":XUAT_ID",":HH_ID");
	$values = array($thu,$hanghoa);
	$types = array(PDO::PARAM_INT,PDO::PARAM_INT);//kiem tra lai kieu du lieu nhe
	$rows = $db->executeQuery($sql, $parameters, $values, $types);
	if ($rows != null) {
	$row = $rows->fetch();
        $chitietxuat=new Chi_tiet_xuat();
		$chitietxuat->setHH_ID($row->HH_ID);
		$chitietxuat->setXUAT_ID($row->XUAT_ID);
		$chitietxuat->setDON_GIA($row->DON_GIA);
		$chitietxuat->setSO_LUONG($row->SO_LUONG);
		$chitietxuat->setTHANH_TIEN($row->THANH_TIEN);
		$chitietxuat->setIS_ACTIVE($row->IS_ACTIVE);
                
                return $chitietxuat;
	}
	
		}
	}
	
	public function getList($db = null) {
	if ($db != null) {
    $sql = "SELECT
			`HH_ID`,
				`XUAT_ID`,
				`DON_GIA`,
				`SO_LUONG`,
				`THANH_TIEN`,
				`IS_ACTIVE`
			FROM `chi_tiet_xuat` WHERE `is_active`=1;";
    $rows = $db->executeQuery($sql);
    $objects = array();
    if ($rows != null) {
    while ($row = $rows->fetch()) {
    $obj = new Chi_tiet_xuat();
    	 $obj->setHH_ID($row->HH_ID);
		 $obj->setXUAT_ID($row->XUAT_ID);
		 $obj->setDON_GIA($row->DON_GIA);
		 $obj->setSO_LUONG($row->SO_LUONG);
		 $obj->setTHANH_TIEN($row->THANH_TIEN);
		 $obj->setIS_ACTIVE($row->IS_ACTIVE);
		$objects[] = $obj;
    }
    return $objects;
    }
        }
    }
}
?>

